<?php
class Signature{
	function __construct(){
		$this->data = array();
	}
	function add_data($str){
		array_push($this->data, (string)$str);
	}
	function get_signature(){
		sort( $this->data, SORT_STRING );
		return sha1( implode( $this->data ) );
	}
};
$appId = 'wxcc07ac63283d591d';
$secret = 'a58ff6f8f2747c125ee0d5ee556fb1ce';
include_once 'jssdk.php';
$jssdk = new JSSDK($appId, $secret);
$signPackage = $jssdk->GetSignPackage();

$query=$mysqli->query("select ci from users where openid='".$openid."' limit 0,1 ");
if($query->num_rows>0){
	$userInfo=$query->fetch_array();
	$ciShu=(int)$userInfo['ci'];
}else{
	exit;
}
$userList=array();
$query=$mysqli->query("select fname,favatar from friend where openid='".$openid."'  ");
$count=0;
if($query->num_rows>0){
	while ($list=$query->fetch_array()){
		$userList[] =array('img'=>$list['favatar'], 'name'=>$list['fname']);
		$count++;
	}
}
$mysqli->close();

if ($ciShu >= 50){
	$acToken=$jssdk->getAccessToken();
	$apiTicket=json_decode(file_get_contents('https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='.$acToken.'&type=wx_card'), true);
	$api_ticket=$apiTicket['ticket'];
	$card_id='pieCpuCSYcYc6pvanMRMtgcIScks';
	$timestamp=time();
	$signature = new Signature();
	$signature->add_data($api_ticket);
	$signature->add_data($timestamp);
	$signature->add_data($card_id);
	$signature->add_data($openid);
	$sign=$signature->get_signature();
}
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>德尔地板风云惠</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<link href="http://tu-10030004.file.myqcloud.com/tk/ui.css" rel="stylesheet">
<style>
html,body{font-size:16px;background:#090f25;width:100%;font-size:12px;color:#fff;font-family:Microsoft YaHei, Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;}
body, div{position:relative;padding:0px;margin:0px auto;max-width:640px;}
-webkit-touch-callout:none;
-webkit-user-select:none;
html{-ms-touch-action:none;}
div,img{-webkit-tap-highlight-color:rgba(0,0,0,0);}
*{-webkit-text-size-adjust: none;}
.simg{position:absolute;display:block;}
a{text-decoration:none;}
.container{position:relative;width:100%;height:auto;}
.hide{display:none;}
input{position:absolute;display:block;text-indent:10px;-webkit-appearance:none;background:none;padding:0;outline-style:none;border:none;color:#000;}
select{position:absolute;display:block;background:transparent;border:0px;text-indent:10px;font-size:12px;-webkit-appearance:none;}
.user{position:absolute;width:100%;height:100%;display:none;background:transparent url('./img/p2.jpg') no-repeat;background-size:cover;}
.user-txt{position:absolute;width:100%;font-size:16px;left:0px;text-align:center;font-weight:700;}
.t-bg{position:absolute;width:100%;height:100%;background-color:#022577;opacity:.8;z-index:9;top:0px;left:0px;display:none;}
.t-j{position:absolute;width:100%;height:100%;z-index:99;top:0px;left:0px;display:none;}
.rule{position:absolute;width:100%;height:100%;display:none;background:transparent url('./img/p2.jpg') no-repeat;background-size:cover;}
.friend{position:absolute;width:100%;height:100%;display:none;background:transparent url('./img/friend.jpg') no-repeat;background-size:cover;}
.friend-list{position:absolute;height:auto;padding-top:2px;margin:0px auto;overflow-y:scroll;overflow-x:hidden;}
<?php if ($count > 5){ ?>
.friend-list::-webkit-scrollbar-thumb{border-radius:10px;height:30%;background-color:#3272b0;  }
.friend-list::-webkit-scrollbar{border-radius:10px;width:5px;background-color:#dfe8f1;}
<?php }else{ ?>
.friend-list{overflow-y:hidden;}
<?php } ?>
.friend-user{position:relative;margin-bottom:5px;}
.f-avatar{border-radius:50%;}
.f-name{position:absolute;text-align:left;overflow:hidden;}
.dui{position:absolute;width:100%;height:100%;display:none;background:transparent url('./img/dui.jpg') no-repeat;background-size:cover;}
.cha{position:absolute;width:100%;height:100%;display:none;background:transparent url('./img/cha.jpg') no-repeat;background-size:cover;}
.friend-txt{position:absolute;font-size:14px;font-weight:700;}
</style>
</head>
<body>
<div class="container"> 
  <div class="user">
  	   <img class="user-t1 simg" src="./img/user-t1.png?v=1">
  	   <div class="user-t2 user-txt">累计已获得</div>
  	   <div class="user-t3 user-txt"><?php echo $ciShu; ?>次好友助力</div>
  	   <div class="user-dh simg"></div>
  	   <div class="user-invite simg"></div>
  	   <div class="user-friend simg"></div>
  	   <div class="user-rule simg"></div>
  	   <div class="user-back simg"></div> 
  </div>
  <div class="rule">
  	<img class="rule-t1 simg" src="./img/rule-t2.png?v=1">
  	<div class="rule-g simg"></div> 
  </div>
  <div class="friend">
      <div class="friend-txt">已有 <?php echo $count; ?> 位好友位你助力加油:</div>
  	  <div class="friend-list">
           <?php foreach ($userList as $k => $v){ ?>
	         <div class="friend-user"><img class="f-avatar" src="<?php echo $v['img'] ?>" /><span class="f-name"><?php echo $v['name'] ?></span></div>
	       <?php } ?>
	  </div>
  	  <div class="friend-back simg"></div> 
  </div>
  <div class="dui">
      <div class="dui-run simg"></div>
      <div class="dui-back simg"></div>
  </div>
  <div class="cha">
      <div class="cha-back simg"></div>
  </div>
  <div class="t-bg"></div>
   <div class="t-j share">
         <img class="share-t1 simg" src="./img/share.png">
   </div>
  <div class="weui_dialog_alert" id="alert" style="display:none;">
	    <div class="weui_mask"></div>
	    <div class="weui_dialog">
	        <div class="weui_dialog_hd"><strong class="weui_dialog_title alert_title"></strong></div>
	        <div class="weui_dialog_bd alert_msg"></div>
	        <div class="weui_dialog_ft">
	            <a href="javascript:;" class="weui_btn_dialog primary">确定</a>
	        </div>
	    </div>
  </div>
   
     
</div> 
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="http://tu-10030004.file.myqcloud.com/js/pxloader-images.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
h= Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
var sWidth = parseInt((window.innerWidth > 0) ? window.innerWidth : screen.width);
if(sWidth>640){sWidth=640;}
var _rate=(sWidth/640);
var _img=['p2.jpg'];
var loader = new PxLoader();
for(var i=0; i<_img.length; i++){loader.addImage('img/'+_img[i]);}
var _startGame=true;
loader.start();
loader.addCompletionListener(function(e) {
	 $(".user").show();
});
if(h<_rate*1040){
	h=_rate*1040;
}
_count='<?php echo $ciShu; ?>';
$(function(){
	$('.container').width(sWidth).height(_rate*1040);
	$('.user, .user-t1').width(sWidth).height(_rate*1040); 
	$('.user-t2').height(_rate*80).css({"top":_rate*296, "lineHeight":_rate*80+"px"});
	$('.user-t3').height(_rate*80).css({"top":_rate*360, "lineHeight":_rate*80+"px"});
	$('.user-dh').width(_rate*220).height(_rate*60).css({"top":_rate*744, "left":_rate*70});
	$('.user-invite').width(_rate*220).height(_rate*60).css({"top":_rate*744, "right":_rate*70});
	$('.user-friend').width(_rate*220).height(_rate*60).css({"top":_rate*826, "left":_rate*70});
	$('.user-rule').width(_rate*220).height(_rate*60).css({"top":_rate*826, "right":_rate*70});
	$('.user-back').width(_rate*200).height(_rate*60).css({"top":_rate*920, "left":_rate*220});
	$('.share-t1').width(sWidth).height(_rate*549).css({"top":_rate*20, "left":0});
	$('.rule, .rule-t1').width(sWidth).height(_rate*1040); 
	$('.rule-g').width(_rate*180).height(_rate*70).css({"top":_rate*902, "left":_rate*230});
	$('.friend-txt').width(_rate*540).css({"top":_rate*196, "left":_rate*90});
	$('.friend-list').width(_rate*400).height(_rate*580).css({"top":_rate*270, "left":_rate*90});
	$('.friend-user').width(_rate*400).height(_rate*60);
	$(".f-avatar").width(_rate*56).height(_rate*56);
	$(".f-name").width(_rate*330).height(_rate*60).css({"top":_rate*10, "left":_rate*70});
	$('.friend-back').width(_rate*180).height(_rate*70).css({"top":_rate*902, "left":_rate*230});
	$('.dui-run').width(_rate*140).height(_rate*60).css({"top":_rate*796, "left":_rate*122});
	$('.dui-back').width(_rate*140).height(_rate*60).css({"top":_rate*796, "right":_rate*122});
	$('.cha-back').width(_rate*150).height(_rate*60).css({"top":_rate*776, "right":_rate*242});

	wx.config({
		appId: '<?php echo $signPackage["appId"];?>',timestamp: <?php echo $signPackage["timestamp"];?>,
		nonceStr: '<?php echo $signPackage["nonceStr"];?>',signature: '<?php echo $signPackage["signature"];?>',
		jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage','onMenuShareQQ','showMenuItems','showOptionMenu','addCard','chooseCard','openCard']
	});
	wx.ready(function () {
		    var _title='德尔地板风云惠';
		    var _desc='帮我助力加油，赢取德尔地板风云惠一折众筹券';
		    var _link='http://mei94.com/fyh/?a=wan&op=<?php echo $openid; ?>';
		    var _imgUrl='http://mei94.com/fyh/img/64.jpg';
			wx.onMenuShareTimeline({title: _title, link: _link, imgUrl: _imgUrl,success: function () {},cancel: function () { }});
			wx.onMenuShareAppMessage({ title: _title, desc: _desc,link: _link,imgUrl: _imgUrl, type: '', dataUrl: '', success: function () {},cancel: function () {  }});  	
	});
	$('.cha-back').click(function(){
		$(".cha").fadeOut();
        $(".user").fadeIn();
    });
    <?php if ($ciShu >= 50){ ?>
    var _canDui=true;
	$('.dui-run').click(function(){
		if(false == _canDui){return;}
		wx.addCard({
  	      cardList: [
  	        {
  	          cardId: '<?php echo $card_id; ?>',
  	          cardExt: '{"openid": "<?php echo $openid; ?>", "timestamp": "<?php echo $timestamp; ?>", "signature":"<?php echo  $sign; ?>"}'
  	        }
  	      ],
  	      success: function (res) {
  	    	$.post("?a=jian", {op:'<?php echo $openid ?>'}, function(data){
  	         }, "json");
  	    	$(".dui").fadeOut();
	        $(".cha").fadeIn();
	        _count=_count-50;
	        $(".user-t3").html(_count+'次好友助力');
	        _canDui=false;
  	      },
  	      cancel: function (res) {
  	    	_canDui=true;
  	      }
  	    });
    });
	$('.dui-back').click(function(){
		$(".dui").fadeOut();
        $(".user").fadeIn();
    });
 
    <?php } ?>

	$('.friend-back').click(function(){
		$(".friend").fadeOut();
        $(".user").fadeIn();
    });
	$('.user-friend').click(function(){
		$(".user").fadeOut();
        $(".friend").fadeIn();
    });
	$('.user-rule').click(function(){
		$(".user").fadeOut();
        $(".rule").fadeIn();
    });
	$('.rule-g').click(function(){
		$(".rule").fadeOut();
        $(".user").fadeIn();
    });
	$('.user-back').click(function(){
		 window.location.href="game.php";
    });
	$('.user-invite').click(function(){
         $(".t-bg, .share").fadeIn();
    });
	$(".t-bg, .share").click(function(){
        $(".t-bg, .share").fadeOut();
    });
	$('.user-dh').click(function(){
       if(_count<50){
    	  $(".alert_msg").html("助力值小于50，暂无法兑换");
		  $("#alert").show();
          return;
       }
       $(".dui").fadeIn();
       $(".user").fadeOut();
    });

	
	 
	$('.weui_btn_dialog').click(function(){
		$("#alert").hide(); 
	});
	 
});
</script>
</body>
</html>